
(function(win){
var util ={

	/*设备检测*/
	deviceCheck:(function(){
		var UA = navigator.userAgent;
		var isIphone = /iphone|ipod|ipad/gi.test(UA);
		var isAndroid = /android/gi.test(UA);
		var isPhone = /iphone|ipod|ipad|android/gi.test(UA);
		if(isIphone){
			return 1;
		}
		if(isAndroid){
			return 2;
		}
		if(!isPhone){
			return 3;
		}
	})(),

	/*获取数据*/
	getData:function(obj){
		$.ajax({
			url:obj.url,
			data:obj.parm,
			dataType:"jsonp",
			jsonp:"callback",
			success:function(data){
				obj.success_callback(data);
			}
		})
	},
    
 
	getQueryString:function(name) {
	    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	    var r = window.location.search.substr(1).match(reg);
	    if (r != null) return decodeURIComponent(r[2]); return null;
	},
	 
	getRequest:function() {
	   var url = location.search;  
	   if (url.indexOf("?") != -1) {     
	      var str = url.substr(1);  
	      strs = str.split("=");     
	      return strs[1].split('&')[0]; 
	   }
	},

	/*拷贝*/
	copyprop:function( a, b ) {
		for( var key in b ) { 
			if( b.hasOwnProperty( key ) ) {
				a[key] = b[key];
				console.log(key);
			}
		}
		return a;
	},

	/*动态设置标题*/
	titleSetting:function(title){
		var $body = $('body');
        document.title = title;
        var $iframe = $('<iframe class="titleseting" src="statics/img/ico.png"></iframe>');
        $iframe.on('load',function() {
            setTimeout(function() {
                $iframe.off('load').remove();
            }, 0);
        }).appendTo($body);
	},
	/*延时加载*/
	ldz:function(elem){
            var win_height=$(window).height();
            $(elem).each(function(){
                  var top = $(this).offset().top;
                  if(top<win_height){
                        var img=$(this).attr("data-src");
                         $(this).attr("src",img);
                         $(this).addClass("active");
                  }
            })
            $(window).scroll(function(){
                   var scrollTop = $(this).scrollTop();
                   $(elem).each(function(){
                        var offsetTop = $(this).offset().top;
                        var top=offsetTop-scrollTop;
                        if(top<win_height){
                              var ok=$(this).attr("data-ok");
                              if(!ok){
                               var img=$(this).attr("data-src");
                                     $(this).attr("src",img);
                                     $(this).addClass("active");
                                     console.log("isok");
                              }
                              $(this).attr("data-ok","1");
                        }

                     })
          });
    },
    dialog : (function(){
		function alerts(options){
				domadd(options);
		}

		function domadd(options){
			var title= options.title || 'higo up',
			type = options.type || 2,
			 cancel = options.cancel || '取消',
			 confirm = options.confirm || '确定',
	         cancelcallbcak = options.cancelcallbcak || "",
	         confirmcallback = options.confirmcallback || "",
	         anthercallback = options.anthercallback || "";

			 if($("body").hasClass("addd")){
				  $(".alersection").show();
			 }else{
			 	 //有cancel
			 	if(type ==1){
			 		var cancel=	"<div class='cancel linecenter flex'>"+cancel+"</div>";
			 	}else{
			 		cancel="";
			 	}
				var divback="<div class='alersection'>"+
				"<div class='alertbac'></div>"+
				"<div class='dialogsec'>"+
					"<div class='abs'>"+
					 "<div class='dialogtitle linecenter'>"+title+"</div>"+
					 "<div class='dialogbtn disflex'>"+
					 		cancel+
					 		"<div class='confirm linecenter flex'>"+confirm+"</div>"+
					 "</div>"+
					"</div>"+
				"</div>"+
				"</div>";
			    $("body").append(divback);
			    $("body").addClass("addd");

			   $(".dialogsec").addClass("fadeInfast");
			}
			//取消按钮
	        if(cancelcallbcak && typeof cancelcallbcak =="function"){
			    $(".cancel").click(function(){

			    	if(cancelcallbcak && typeof cancelcallbcak == "function"){
			    		cancelcallbcak();
			    	}else{
			    		$(".alersection").hide();
			    	}
			    	
			    })
			}
			//确定按钮
			
		    $(".confirm").click(function(){
		    	if(confirmcallback && typeof confirmcallback =="function"){
		    		confirmcallback();
		    	}else{
		    		$(".alersection").hide();
		    	}
		    	
		    })
			 

			
			//其他
			if(anthercallback && typeof anthercallback =="function"){
			    anthercallback();
			}
		}

		return {
			alert:alerts
		}

	})()

}
 
util.copyprop(window,util);

})(window)


